1. Technical Field
The present invention relates in general to the data processing field. More specifically, the present invention relates to object oriented computer programming techniques.
2. Background Art
Since the dawn of the computer age, computer systems have evolved into extremely sophisticated devices, and computer systems may be found in many different settings. Computer systems typically include a combination of hardware (e.g., semiconductors, circuit boards, etc.) and software (e.g., computer programs). As advances in semiconductor processing and computer architecture push the performance of the computer hardware higher, more sophisticated computer software has evolved to take advantage of the higher performance of the hardware, resulting in computer systems today that are much more powerful than just a few years ago.
Computer systems typically include operating system software that controls the basic function of the computer, and one or more software application programs that run under the control of the operating system to perform desired tasks. For example, a typical IBM Personal Computer may run the OS/2 operating system, and under the control of the OS/2 operating system, a user may execute an application program, such as a word processor. As the capabilities of computer systems have increased, the application software programs designed for high performance computer systems have become extremely powerful. Additionally, software development costs have continued to rise because more powerful and complex programs take more time, and hence more money, to produce.
One way in which the performance of application software programs has been improved while the associated development costs have been reduced is by using object-oriented programming concepts. The goal of using object-oriented programming is to create small, reusable sections of program code known as xe2x80x9cobjectsxe2x80x9d that can be quickly and easily combined and re-used to create new programs. This is similar to the idea of using the same set of building blocks again and again to create many different structures. The modular and re-usable aspects of objects will typically speed development of new programs, thereby reducing the costs associated with the development cycle. In addition, by creating and re-using a comprehensive set of well-tested objects, a more stable, uniform, and consistent approach to developing new computer programs can be achieved.
A central concept in object-oriented programming is the xe2x80x9cclass.xe2x80x9d A class is a template that defines a type of object. A class outlines or describes the characteristics or makeup of objects that belong to that class. By defining a class, objects can be created that belong to the class without having to rewrite the entire definition for each new object as it is created. This feature of object-oriented programming promotes the reusability of existing object definitions and promotes more efficient use of program code.
When an object is created in an object oriented system, it is created as an instance of a particular class. Object oriented languages typically define methods on a class that create and delete objects when the methods are invoked. The creation of an object typically involves two operations: 1) allocating storage for the object, and 2) invoking the constructor method on the class, which creates the instance of the class in the allocated storage.
Most object oriented computer systems include a xe2x80x9cheapxe2x80x9d, which is a relatively large storage area that may be allocated in smaller pieces as needed. In the prior art, when an object needs to be created, a storage element must typically be retrieved from the heap. The object can then be created using the storage element. However, the act of retrieving storage from the heap generally takes a relatively long time, resulting in substantial performance penalties when a storage element is allocated for an object. Furthermore, accesses to storage elements must be serialized on multi-threaded systems. Serializing access to storage elements assures that one storage element cannot be allocated to two different threads. Serialization is accomplished using a locking scheme. When one thread is accessing the heap, other threads are locked out, effectively serializing the access of threads that desire simultaneous access. Without locking, it would be possible for two threads to check the heap and determine that the same storage element is available, but the storage element can only be allocated to one of the threads. Serialization is the technique used to assure that a storage element can only be allocated to one thread.
Modern object oriented programming languages have features that improve the convenience of programming in those languages. For example, the Java programming language developed by Sun Microsystems has a garbage collection feature that automatically returns unused objects to the heap. Automatic garbage collection has the advantage of reducing the complexity of the code because explicit code to return objects to the heap is not required. However, this advantage comes at a cost in performance and flexibility. Allocating an object from the heap is a relatively expensive process in terms of computer resources. By automatically returning old objects to the heap during garbage collection, a storage element must be re-allocated from the heap as each new object is created. One way to overcome part of the performance penalty of automatic garbage collection is to create groups of objects known as object pools (or storage pools) that are still in use as far as the garbage collection mechanism is concerned, but are actually not used. When a new object is needed, one of these objects in the pool can be returned without going to the heap to allocate a new storage element. Pools thus provide one way to xe2x80x9crecyclexe2x80x9d used objects in a way that provides significant performance benefits. However, using object pools requires that serialization methods must still be employed to assure that an object in the pool is allocated to only one thread. While object pools enhance the performance of an object oriented program that has automatic garbage collection, this enhancement is reduced by the serialization techniques used to access the object pool. Without a mechanism for allowing different threads to access an object pool simultaneously, the computer industry will continue to suffer performance penalties in object oriented programs that use object pools due to the serialization of accesses to the object pool.
A threadsafe object pool in accordance with the preferred embodiments reserves each object for a particular thread of execution. Locking of an object pool is normally required to assure that two threads cannot simultaneously request the same object. However, because each object in the pool is reserved for a single thread, no other threads will be allowed to access the object, so the locking of the pool to prevent simultaneously allocating an object to two different threads is not required.
The foregoing and other features and advantages of the invention will be apparent from the following more particular description of preferred embodiments of the invention, as illustrated in the accompanying drawings.